/*
 *   This File is Part of CuteOgre Game Engine
 *
 *   This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 *	Copyright 2010 Alexandre Pires ( c.alexandre.pires@gmail.com )
 *  Created on: 2010/08/22
 */


#ifndef VideoPlayer_H_
#define VideoPlayer_H_

#include "Ogg/OggFile.h"
#include "SoundSource.h"

#include <QObject>
#include <QTime>
#include <QMutex>

#include "OGRE/OgreFrameListener.h"
#include "OGRE/OgreTexture.h"
#include "OGRE/OgreOverlayManager.h"
#include "OGRE/OgreOverlayContainer.h"
#include "OGRE/OgreMaterial.h"

class VideoPlayer: public QObject, public Ogre::FrameListener {
	Q_OBJECT
	enum VideoPlayerState {
		VPS_NOVIDEO = 0x0,
		VPS_LOADING = 0x1,
		VPS_PLAYING = 0x2
	};
public:
	VideoPlayer ( QObject* rParent = 0 );
	virtual ~VideoPlayer();
public:
	bool isPlaying () const { return mPlaying; }
	void playVideo ( OggFilePtr rVideoFile );
	VideoPlayerState update ();
	void releaseCurrentVideo ();
	bool frameStarted(const Ogre::FrameEvent& evt);
	bool frameRenderingQueued(const Ogre::FrameEvent& evt);
    bool frameEnded(const Ogre::FrameEvent& evt);
private:
	QTime mTime;
	bool mPlaying;
	OggFilePtr mVideo;
    Ogre::TexturePtr mVideoTexture;
    VideoPlayerState mCurrentState;
    QMutex mMutex;
    SoundSourcePtr mSound;
    Ogre::Overlay* mOverlay;
    Ogre::OverlayContainer* mFrameContainer;
    Ogre::MaterialPtr mVideoFrame;
};

#endif /* VideoPlayer_H_ */
